package ${jsonPackage};

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import ${entityPackage}.${domainObjectName};
import ${entityPackage}.${domainObjectName}Key;
import ${pagingInfo}.PagingInfo;
import ${paramsValidate}.ParamsValidate;
import ${servicePackage}.${domainObjectName}Service;

import java.util.List;

@Controller
@RequestMapping("/${lowerDomainObjectName}")
public class ${domainObjectName}Json {
    @Autowired
    ${domainObjectName}Service ${lowerDomainObjectName}Service;

    @RequestMapping("pagingList.json")
    @ResponseBody
    public Object pagingList(Model model,PagingInfo pagingInfo) {
        return ${lowerDomainObjectName}Service.pagingList(pagingInfo);
    }

    @RequestMapping("list.json")
    @ResponseBody
    public Object list(Model model) {
        return ${lowerDomainObjectName}Service.list();
    }
    
    @RequestMapping("selectByPrimaryKey.json")
    @ResponseBody
    public Object selectByPrimaryKey(Model model,@RequestParam("id")${domainObjectName}Key id) {
        return ${lowerDomainObjectName}Service.selectByPrimaryKey(id);
    }
    
    @RequestMapping("saveOrUpdateUser.json")
    @ResponseBody
    @ParamsValidate
    public Object saveOrUpdate(Model model,${domainObjectName} ${lowerDomainObjectName}) {
//    	${lowerDomainObjectName}.setUserPassword(null);
    	${lowerDomainObjectName}Service.saveOrUpdate(${lowerDomainObjectName});
        return null;
    }

    @RequestMapping("delete.json")
    @ResponseBody
    public Object delete(Model model,@RequestBody String body) {
        List<${domainObjectName}Key> ids = JSON.parseArray(body,${domainObjectName}Key.class);
    	${lowerDomainObjectName}Service.delete(ids);
        return null;
    }
}
